$(function () {
    $('.list-left ul li').click(function () {
        var navnum = $(this).index();
        sessionStorage.setItem("navnum", navnum);
    });
    $(function () {
        var getnavnum = sessionStorage.getItem("navnum");
        $('.list-left ul li').eq(getnavnum).addClass("active").siblings().removeClass("active");
    })
});

$(function () {
    $('.pwd').click(function () {
        $('.page-pwd').fadeIn();
        $('#hidebg').removeClass("hidebg").addClass("nohidebg");
    });
    $('.button_cancel').click(function () {
        $('.page-pwd').fadeOut();
        $('#hidebg').removeClass("nohidebg").addClass("hidebg");
    });
});

$(function () {
    var $table = $("table");
    var currentPage = 0; //当前页默认值为0  
    var pageSize = 8; //每一页显示的数目  
    $table.bind('paging', function () {
        $table.find('tbody tr').hide().slice(currentPage * pageSize, (currentPage + 1) * pageSize).show();
    });
    var sumRows = $table.find('tbody tr').length;
    var sumPages = Math.ceil(sumRows / pageSize); //总页数  

    var $pager = $('<div class="page"></div>'); //新建div，放入a标签,显示底部分页码  
    for (var pageIndex = 0; pageIndex < sumPages; pageIndex++) {
        $('<a href="#" id="pageStyle" class="pageStyle" onclick="changCss(this)"><span>' + (pageIndex + 1) + '</span></a>').bind("click", {
            "newPage": pageIndex
        }, function (event) {
            currentPage = event.data["newPage"];
            $table.trigger("paging");
            //触发分页函数  
        }).appendTo($pager);
        $pager.append(" ");
    }
    $pager.insertAfter($table);
    $table.trigger("paging");

    //默认第一页的a标签效果  
    var $pagess = $('#pageStyle');
    $pagess[0].style.backgroundColor = "#2795dc";
    $pagess[0].style.color = "#ffffff";
});

//a链接点击变色，再点其他回复原色  
function changCss(obj) {
    var arr = document.getElementsByClassName("pageStyle");
    for (var i = 0; i < arr.length; i++) {
        if (obj == arr[i]) { //当前页样式  
            obj.style.backgroundColor = "#2795dc";
            obj.style.color = "#ffffff";
        } else {
            arr[i].style.color = "#8c8787";
            arr[i].style.backgroundColor = "#ffffff";
        }
    }
}

function checkNpwd() {
    var flag = true;
    var npwd = document.getElementById('npwd').value;
    document.getElementById('npwdinfo').innerHTML = " ";
    if (npwd == "") {
        document.getElementById('npwdinfo').innerHTML = "✲ 新密码不能为空";
        flag = false;
    } else if (npwd.length < 6) {
        document.getElementById('npwdinfo').innerHTML = "✲ 密码至少为六位";
        flag = false;
    }
    return flag;
}

function checkRenpwd() {
    var flag = true;
    var npwd = document.getElementById('npwd').value;
    var renpwd = document.getElementById('renpwd').value;
    document.getElementById('renpwdinfo').innerHTML = " ";
    if (renpwd != npwd) {
        document.getElementById('renpwdinfo').innerHTML = "✲ 两次密码输入不一致";
        flag = false;
    }
    return flag;
}

function checkAll() {
    var flag1 = checkNpwd();
    var flag2 = checkRenpwd();
    var flag = flag1 & flag2;
    if (flag == false) {
        alert('信息填写有误，请检查重试');
    }
    else {
        document.change.action = "userAction.php?method=change";
        document.change.submit();
    }
}

function checkAll2() {
    var flag1 = checkNpwd();
    var flag2 = checkRenpwd();
    var flag = flag1 & flag2;
    if (flag == false) {
        alert('信息填写有误，请检查重试');
    } else {
        document.change.action = "userAction.php?method=s-change";
        document.change.submit();
    }
}

function checkstuNo() {
    var flag = true;
    var stuNo = document.getElementById('stuNo').value;
    document.getElementById('stuNoInfo').innerHTML = " ";
    if (stuNo == "") {
        document.getElementById('stuNoInfo').innerHTML = "✲ 该项不能为空";
        flag = false;
    }
    else return flag;
}

function checkstuName() {
    var flag = true;
    var stuName = document.getElementById('stuName').value;
    document.getElementById('stuNameInfo').innerHTML = " ";
    if (stuName == "") {
        document.getElementById('stuNameInfo').innerHTML = "✲ 该项不能为空";
        flag = false;
    }
    else return flag;
}

function checkstuTel() {
    var flag = true;
    var stuTel = document.getElementById('stuTel').value;
    document.getElementById('stuTelInfo').innerHTML = " ";
    if (stuTel == "") {
        document.getElementById('stuTelInfo').innerHTML = "✲ 该项不能为空";
        flag = false;
    }
    else return flag;
}

function checkstuAddress() {
    var flag = true;
    var stuAddress = document.getElementById('stuAddress').value;
    document.getElementById('stuAddressInfo').innerHTML = " ";
    if (stuAddress == "") {
        document.getElementById('stuAddressInfo').innerHTML = "✲ 该项不能为空";
        flag = false;
    }
    else return flag;
}

function checkstuInfo() {
    var flag1 = checkstuNo();
    var flag2 = checkstuName();
    var flag3 = checkstuTel();
    var flag4 = checkstuAddress();
    var flag = flag1 & flag2 & flag3 & flag4;
    if (flag == false) {
        alert('信息填写不完整，请检查补充完整');
    }
    else {
        document.addform.action = "userAction.php?method=add";
        document.addform.submit();
    }
}

function checkstuInfo2() {
  var flag1 = checkstuName();
  var flag2 = checkstuTel();
  var flag3 = checkstuAddress();
    var flag = flag1 & flag2 & flag3;
  if (flag == false) {
    alert("信息填写不完整，请检查补充完整");
  } else {
    document.addform.action = "userAction.php?method=alter-n";
    document.addform.submit();
  }
}

function checkstaInfo() {
    var flag1 = checkstuNo();
    var flag2 = checkstuName();
    var flag3 = checkstuTel();
    var flag4 = checkstuAddress();
    var flag = flag1 & flag2 & flag3 & flag4;
    if (flag == false) {
        alert('信息填写不完整，请检查补充完整');
    }
    else {
        document.addform.action = "userAction.php?method=sta-add";
        document.addform.submit();
    }
}

function checkstaInfo2() {
    var flag1 = checkstuName();
    var flag2 = checkstuTel();
    var flag3 = checkstuAddress();
    var flag = flag1 & flag2 & flag3;
    if (flag == false) {
        alert("信息填写不完整，请检查补充完整");
    } else {
        document.addform.action = "userAction.php?method=sta-alter-n";
        document.addform.submit();
    }
}

function checkspeNo() {
    var flag = true;
    var speNo = document.getElementById('speNo').value;
    document.getElementById('speNoInfo').innerHTML = " ";
    if (speNo == "") {
        document.getElementById('speNoInfo').innerHTML = "✲ 该项不能为空";
        flag = false;
    }
    else return flag;
}

function checkspeName() {
    var flag = true;
    var speName = document.getElementById('speName').value;
    document.getElementById('speNameInfo').innerHTML = " ";
    if (speName == "") {
        document.getElementById('speNameInfo').innerHTML = "✲ 该项不能为空";
        flag = false;
    }
    else return flag;
}

function checkstaffNo() {
    var flag = true;
    var staffNo = document.getElementById('staffNo').value;
    document.getElementById('staffNoInfo').innerHTML = " ";
    if (staffNo == "") {
        document.getElementById('staffNoInfo').innerHTML = "✲ 该项不能为空";
        flag = false;
    }
    else return flag;
}
function checkclassno() {
    var flag = true;
    var classno = document.getElementById('classno').value;
    document.getElementById('classnoInfo').innerHTML = " ";
    if (classno == "") {
        document.getElementById('classnoInfo').innerHTML = "✲ 该项不能为空";
        flag = false;
    }
    else return flag;
}

function checkclassName() {
    var flag = true;
    var className = document.getElementById('className').value;
    document.getElementById('classNameInfo').innerHTML = " ";
    if (className == "") {
        document.getElementById('classNameInfo').innerHTML = "✲ 该项不能为空";
        flag = false;
    }
    else return flag;
}

function checkclassNumber() {
    var flag = true;
    var classNumber = document.getElementById('classNumber').value;
    document.getElementById('classNumberInfo').innerHTML = " ";
    if (classNumber == "") {
        document.getElementById('classNumberInfo').innerHTML = "✲ 该项不能为空";
        flag = false;
    }
    else return flag;
}
function checkcourseNo() {
    var flag = true;
    var courseNo = document.getElementById('courseNo').value;
    document.getElementById('courseNoInfo').innerHTML = " ";
    if (courseNo == "") {
        document.getElementById('courseNoInfo').innerHTML = "✲ 该项不能为空";
        flag = false;
    }
    else return flag;
}

function checkspeAddress() {
    var flag = true;
    var speAddress = document.getElementById('speAddress').value;
    document.getElementById('speAddressInfo').innerHTML = " ";
    if (speAddress == "") {
        document.getElementById('speAddressInfo').innerHTML = "✲ 该项不能为空";
        flag = false;
    }
    else return flag;
}

function checkspeInfo() {
    var flag1 = checkspeNo();
    var flag2 = checkspeName();
    var flag3 = checkstaffNo();
    var flag4 = checkcourseNo();
    var flag5 = checkspeAddress();
    var flag = flag1 & flag2 & flag3 & flag4 & flag5;
    if (flag == false) {
        alert('信息填写不完整，请检查补充完整');
    }
    else {
        document.addform.action = "userAction.php?method=spe-add";
        document.addform.submit();
    }
}

function checkspeInfo2() {
    var flag1 = checkspeName();
    var flag2 = checkstaffNo();
    var flag3 = checkcourseNo();
    var flag4 = checkspeAddress();
    var flag = flag1 & flag2 & flag3 & flag4;
    if (flag == false) {
        alert("信息填写不完整，请检查补充完整");
    } else {
        document.addform.action = "userAction.php?method=spe-alter-n";
        document.addform.submit();
    }
}
function checkclassInfo() {
    var flag1 = checkclassno();
    var flag2 = checkclassName();
    var flag3 = checkclassNumber();
    var flag4 = checkspeNo();
    var flag = flag1 & flag2 & flag3 & flag4 ;
    if (flag == false) {
        alert('信息填写不完整，请检查补充完整');
    }
    else {
        document.addform.action = "userAction.php?method=class-add";
        document.addform.submit();
    }
}

function checkclassInfo2() {
    var flag1 = checkclassName();
    var flag2 = checkclassNumber();
    var flag3 = checkspeNo();
    var flag = flag1 & flag2 & flag3;
    if (flag == false) {
        alert("信息填写不完整，请检查补充完整");
    } else {
        document.addform.action = "userAction.php?method=class-alter-n";
        document.addform.submit();
    }
}
function checkselectInfo() {
    var flag1 = checkclassno();
    var flag2 = checkclassName();
    var flag3 = checkclassNumber();
    var flag4 = checkspeNo();
	var flag5 = checkstuNo();
    var flag = flag1 & flag2 & flag3 & flag4 & flag5 ;
    if (flag == false) {
        alert('信息填写不完整，请检查补充完整');
    }
    else {
        document.addform.action = "userAction.php?method=select-add";
        document.addform.submit();
    }
}

function checkselectInfo2() {
    var flag1 = checkclassName();
    var flag2 = checkclassNumber();
    var flag3 = checkspeNo();
	var flag4= checkclassno();
    var flag = flag1 & flag2 & flag3 & flag4;
    if (flag == false) {
        alert("信息填写不完整，请检查补充完整");
    } else {
        document.addform.action = "userAction.php?method=select-alter-n";
        document.addform.submit();
    }
}

function checkcourseInfo() {
    var flag1 = checkspeNo();
    var flag2 = checkspeName();
    var flag3 = checkstaffNo();
    var flag4 = checkcourseNo();
    var flag = flag1 & flag2 & flag3 & flag4;
    if (flag == false) {
        alert("信息填写不完整，请检查补充完整");
    } else {
        document.addform.action = "userAction.php?method=cou-add";
        document.addform.submit();
    }
}

function checkcourseInfo2() {
    var flag1 = checkspeName();
    var flag2 = checkstaffNo();
    var flag3 = checkcourseNo();
    var flag = flag1 & flag2 & flag3;
    if (flag == false) {
        alert("信息填写不完整，请检查补充完整");
    } else {
        document.addform.action = "userAction.php?method=cou-alter-n";
        document.addform.submit();
    }
}